<?php
	function render_tree_open($category)
	{
		$subCategories = $category->getSubCategories();
		if(count($subCategories) === 0)
		{
			render_tree_leaf($category);
		}
		else
		{
			echo ' 	<li>';
			echo '	<div class="btn-group">';
			echo '		<a href="dispatch.php?target=category-edit&id='.$category->getID().'"><span class="glyphicon glyphicon-minus">'.$category->getName().'</span></a>';
			
			echo '			<a href="dispatch.php?target=category-edit&id='.$category->getID().'"  ><span class="glyphicon glyphicon-pencil"></span></a>';						  
			echo '			<a href="dispatch.php?target=category-delete&id='.$category->getID().'"  ><span class="glyphicon glyphicon-trash"></span></a>';	
			echo '			<a href="dispatch.php?target=category-add&parentid='.$category->getID().'"  ><span class="glyphicon glyphicon-plus"></span></a>';						  			
			echo ' </div>';
			echo '		<ul>';
			foreach($subCategories as $subCategory)		
				render_tree_open($subCategory);
			echo '		</ul>';
			echo '	</li>';
		}
		
	}
	
	function render_tree_leaf($category)
	{
		echo ' 	<li>';
		echo '	<div class="btn-group">';
		echo '		<a href="dispatch.php?target=category-edit&id='.$category->getID().'"><span class="glyphicon glyphicon-leaf">'.$category->getName().'</span></a>';
		
		echo '			<a href="dispatch.php?target=category-edit&id='.$category->getID().'"  ><span class="glyphicon glyphicon-pencil"></span></a>';						  
		echo '			<a href="dispatch.php?target=category-delete&id='.$category->getID().'"  ><span class="glyphicon glyphicon-trash"></span></a>';						  
		echo '			<a href="dispatch.php?target=category-add&parentid='.$category->getID().'"  ><span class="glyphicon glyphicon-plus"></span></a>';						  
		echo ' </div>';
		echo '	</li>';
	}
?>
	
<div class="tree well">
	<?php 
		$repository=BO::getCategoryBORepository();
		$categoryBOs = $repository->getRootCategoryBOs(); 
		foreach($categoryBOs as $categoryBO)
		 {
			echo '<ul>';
				render_tree_open($categoryBO);
			echo '</ul>';
		 }
	?>	 
</div>		  
 <link href="assets/bootstrap_extn/css/tree.css" rel="stylesheet">
<script src="assets/bootstrap_extn/js/tree.js"></script>